#include "Inf_HX710.h"

/* 实现微秒级延时 */
void Delay_us(uint32_t us)
{
     uint32_t delay = (HAL_RCC_GetHCLKFreq() / 4000000 * us);
     while (delay--)
     ;
}

void Inf_HX710_Init(void)
{
   // Driver_GPIO_HX710();
}

uint32_t Inf_HX710_ReadValue(void)
{
    uint32_t count = 0;
    ADSK_0;
    while (READ_ADDO)
        ;
    Delay_us(5);//T1
    for (uint8_t i = 0; i < 24; i++)
    {
        ADSK_1;
        Delay_us(5);//T3
        count <<= 1;
        ADSK_0;
        
        if (READ_ADDO)
        {
            count |= 1;
        }
        Delay_us(5);//T4
    }
    ADSK_1;//第25个时钟脉冲 表示下一次转换为差分输入10hz
    Delay_us(5);
    count ^= 0x800000;//异或取补码
    ADSK_0;

    return count;
}
